package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.mapper.BedMapper;
import com.example.mybatisplus.mapper.ResidentMapper;
import com.example.mybatisplus.mapper.RoomMapper;
import com.example.mybatisplus.model.domain.Room;
import com.example.mybatisplus.model.dto.BedInfoDTO;
import com.example.mybatisplus.model.dto.MoveDTO;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.model.domain.Building;
import com.example.mybatisplus.model.dto.UnderDTO;
import lombok.Data;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.BedService;
import com.example.mybatisplus.model.domain.Bed;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2024-07-17
 * @version v1.0
 */
@RestController
@RequestMapping("/api/bed")
public class BedController {

    private final Logger logger = LoggerFactory.getLogger( BedController.class );

    @Autowired
    private BedService bedService;
    @GetMapping("disabled")
    public JsonResponse pageList4(BedInfoDTO bedInfoDTO, PageDTO dto) {
        Page<BedInfoDTO> page = bedService.getDisabledBed(bedInfoDTO, dto);
        return JsonResponse.success(page);}
    @Autowired
    private BedMapper bedMapper;
    @PostMapping("moveBed")
    public JsonResponse moveBed(@RequestBody Bed bed){
        boolean b=bedService.updateById(bed);
        return JsonResponse.success(b);

    }
    @GetMapping("/undergraduate_count")
    public ResponseEntity<Map<String, Integer>> getUndergBed(
            @RequestParam String areaname,
            @RequestParam String campusname) {
        int count = bedMapper.getUndergBed(areaname, campusname);
        Map<String, Integer> response = new HashMap<>();
        response.put("undergraduate_count", count);
        return ResponseEntity.ok(response);
    }
    @GetMapping("/teacher_count")
    public ResponseEntity<Map<String, Integer>> getTeacherBed(
            @RequestParam String areaname,
            @RequestParam String campusname) {
        int count = bedMapper.getTeacherBed(areaname, campusname);
        Map<String, Integer> response = new HashMap<>();
        response.put("teacher_count", count);
        return ResponseEntity.ok(response);
    }
    @GetMapping("/master_count")
    public ResponseEntity<Map<String, Integer>> getMasterBed(
            @RequestParam String areaname,
            @RequestParam String campusname) {
        int count = bedMapper.getMasterBed(areaname, campusname);
        Map<String, Integer> response = new HashMap<>();
        response.put("master_count", count);
        return ResponseEntity.ok(response);
    }
    @GetMapping("/doctor_count")
    public ResponseEntity<Map<String, Integer>> getDoctorBed(
            @RequestParam String areaname,
            @RequestParam String campusname) {
        int count = bedMapper.getDoctorBed(areaname, campusname);
        Map<String, Integer> response = new HashMap<>();
        response.put("doctor_count", count);
        return ResponseEntity.ok(response);
    }
    @GetMapping("/rest_count")
    public ResponseEntity<Map<String, Integer>> getRestBed(
            @RequestParam String areaname,
            @RequestParam String campusname) {
        int count = bedMapper.getRestBed(areaname, campusname);
        Map<String, Integer> response = new HashMap<>();
        response.put("rest_count", count);
        return ResponseEntity.ok(response);
    }
    //房源基建
    @GetMapping("/undergraduate")
    public ResponseEntity<Map<String, Integer>> getUndergCount(){
        int count = bedMapper.getUndergCount();
        Map<String, Integer> response = new HashMap<>();
        response.put("undergraduate", count);
        return ResponseEntity.ok(response);
    }
    @GetMapping("/master")
    public ResponseEntity<Map<String, Integer>> getMasterCount(){
        int count = bedMapper.getMasterCount();
        Map<String, Integer> response = new HashMap<>();
        response.put("master", count);
        return ResponseEntity.ok(response);
    }
    @GetMapping("/doctor")
    public ResponseEntity<Map<String, Integer>> getDoctorCount(){
        int count = bedMapper.getDoctorCount();
        Map<String, Integer> response = new HashMap<>();
        response.put("doctor", count);
        return ResponseEntity.ok(response);
    }
    @GetMapping("/teacher")
    public ResponseEntity<Map<String, Integer>> getTeacherCount(){
        int count = bedMapper.getTeacherCount();
        Map<String, Integer> response = new HashMap<>();
        response.put("teacher", count);
        return ResponseEntity.ok(response);
    }

    @GetMapping("/freeundergraduate")
    public ResponseEntity<Map<String, Integer>> getFreeUndergCount(){
        int count = bedMapper.getFreeUndergCount();
        Map<String, Integer> response = new HashMap<>();
        response.put("freeundergraduate", count);
        return ResponseEntity.ok(response);
    }
    @GetMapping("/freemaster")
    public ResponseEntity<Map<String, Integer>> getFreeMasterCount(){
        int count = bedMapper.getFreeMasterCount();
        Map<String, Integer> response = new HashMap<>();
        response.put("freemaster", count);
        return ResponseEntity.ok(response);
    }
    @GetMapping("/freedoctor")
    public ResponseEntity<Map<String, Integer>> getFreeDoctorCount(){
        int count = bedMapper.getFreeDoctorCount();
        Map<String, Integer> response = new HashMap<>();
        response.put("freedoctor", count);
        return ResponseEntity.ok(response);
    }
    @GetMapping("/freeteacher")
    public ResponseEntity<Map<String, Integer>> getFreeTeacherCount() {
        int count = bedMapper.getFreeTeacherCount();
        Map<String, Integer> response = new HashMap<>();
        response.put("freeteacher", count);
        return ResponseEntity.ok(response);
    }
    @PostMapping("releaseBed")
    public JsonResponse releaseBed(@RequestBody Bed bed){
        // 表示是否删除成功
        boolean res= bedService.releaseBed(bed);
        // res.data
        return JsonResponse.success(res);
    }
    @GetMapping("listUnder")
    public JsonResponse pageList1(UnderDTO underDTO, PageDTO dto) {
        Page<UnderDTO> page = bedService.getUnderBed(underDTO, dto);
        return JsonResponse.success(page);

    }
    @GetMapping("listPost")
    public JsonResponse pageList2(UnderDTO underDTO, PageDTO dto) {
        Page<UnderDTO> page = bedService.getPostBed(underDTO, dto);
        return JsonResponse.success(page);

    }
    @GetMapping("listStaff")
    public JsonResponse pageList3(UnderDTO underDTO, PageDTO dto) {
        Page<UnderDTO> page = bedService.getStaffBed(underDTO, dto);
        return JsonResponse.success(page);

    }
    @PostMapping("/moveBeds")
    public ResponseEntity<String> moveBeds(@RequestBody MoveBedsRequest request) {
        bedService.moveBeds(request.getBedIds(), request.getTarget());
        return ResponseEntity.ok("移动成功");
    }
}
@Data
class MoveBedsRequest {
    private List<Integer> bedIds;
    private String target;

    public List<Integer> getBedIds() {
        return bedIds;
    }
    public String getTarget() {
        return target;
    }

}
